import 'package:flutter/material.dart';
import 'package:flutter_getx/res/colors/colors.dart';
import 'package:flutter_getx/res/gaps.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

//Material->Ink->InkWell->Container  这个结构是为了添加背景的情况下有波纹效果  添加阴影时 如果写在Ink中会有问题  写在Container中为好

class ThemeButton extends StatelessWidget {

  const ThemeButton({
    Key? key,
    this.text = '',
    this.fontSize = 16.0,
    this.fontWeight,
    this.textColor,
    this.disabledTextColor,
    this.bgColors,
    this.disabledBackgroundColor,
    this.shadowColor,
    this.disabledShadowColor,
    this.height = 49.0,
    this.width = double.infinity,
    this.padding = const EdgeInsets.symmetric(horizontal: 8.0),
    this.radius = 4.0,
    this.enable = true,
    this.iconLeft,
    this.iconRight,
    this.iconPadding,
    required this.onPressed,
  }) : super(key: key);

  final String text;
  final double fontSize;
  final FontWeight? fontWeight;
  final Color? textColor;
  final Color? disabledTextColor;
  final List<Color>? bgColors;
  final Color? disabledBackgroundColor;
  final Color? shadowColor;
  final Color? disabledShadowColor;
  final double height;
  final double width;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry padding;
  final double radius;
  final bool enable;
  final Widget? iconLeft;
  final Widget? iconRight;
  final EdgeInsets? iconPadding;

  @override
  Widget build(BuildContext context) {
    return Material(
      borderRadius: BorderRadius.circular(radius.w),
      child: Ink(
        decoration: BoxDecoration(
          gradient: enable ? LinearGradient(colors: bgColors ?? [
                  const Color(0xff6ECEDA),
                  const Color(0xff92DFC0),
                ])
              : LinearGradient(colors: [
                  disabledBackgroundColor ?? (const Color(0xffC4C4C4)),
                  disabledBackgroundColor ?? (const Color(0xffC4C4C4))
                ]),
          borderRadius: BorderRadius.circular(radius.w),
        ),
        child: InkWell(
          borderRadius: BorderRadius.circular(radius.w),
          onTap: enable ? onPressed : null,
          splashColor: colorMain.withOpacity(0.1),
          child: Container(
            padding: padding,
            alignment: Alignment.center,
            width: width == double.infinity ? double.infinity : width.w,
            height: height.w,
            decoration: BoxDecoration(
              boxShadow: <BoxShadow>[
                BoxShadow(
                    color: (enable ? shadowColor : disabledShadowColor) ?? Colors.transparent,
                    offset: const Offset(0.0, 15.0),
                    blurRadius: radius, //模糊程度
                    spreadRadius: -13, //扩散 负数会往上收  这里offset y = 15  这里收起13 剩下2在外面
                ),
              ],
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                iconLeft??Gaps.empty,
                iconLeft == null || iconPadding == null ? Gaps.empty : SizedBox(width: iconPadding!.left,),
                Text(
                  text,
                  style: TextStyle(
                    color: enable ? textColor ?? colorText
                        : disabledTextColor ?? colorText,
                    fontSize: ScreenUtil().setSp(fontSize),
                    fontWeight: fontWeight ?? FontWeight.bold,
                  ),
                ),
                iconRight == null || iconPadding == null ? Gaps.empty : SizedBox(width: iconPadding!.right,),
                iconRight??Gaps.empty,
              ],
            ),
          ),
        ),
      ),
    );
  }
}
